import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

public class DatabaseStations{
	
	private Connection conn;
	private Statement stmt;
	
	private HashMap<Integer, Integer> stations;
	
	public DatabaseStations(){
		connect();
		fillStations();
	}
	
	//Connection for database
	private void connect(){
		try
        {
            String username = "root";
            String password = "";
            String url = "jdbc:mysql://localhost:3306/unwdmi";
            
            Class.forName ("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url, username, password);
            stmt = conn.createStatement();
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
	
	//Get all station from database
	public void fillStations(){
		stations = new HashMap<Integer, Integer>();
		int x = 0;		
		try {
			ResultSet result = stmt.executeQuery("SELECT stn FROM stations ORDER BY STN ASC");
			while(result.next()){
				stations.put(result.getInt(1), x);
				x++;
			}		
		} catch (SQLException e) {			
			e.printStackTrace();
		}		
	}
	
	public HashMap<Integer, Integer> getStations(){
		return stations;
	}
}